<template>
  <basic-container>
    <avue-crud
      ref="crud"
      v-model="form"
      :data="data"
      :option="option"
      :page.sync="page"
      @on-load="rowLoad"
      @search-change="searchChange"
      @row-update="rowUpdate"
      @row-del="rowDel"
      @row-save="rowSave"
      @size-change="sizeChange"
      @current-change="currentChange"
    >
    </avue-crud>
  </basic-container>
</template>

<script>
import avue from "@/mixins/avue.js";
import { baseUrl } from "@/config/env";
import { org_page, org_edit, org_add, org_delete } from "@/api/alumni";

export default {
  mixins: [avue],
  data() {
    return {
      baseUrl,
      data: [],
      option: {
        column: [
          // {
          //   label: "封面",
          //   prop: "cover",
          //   // formslot: true,
          //   type: "upload",
          //   fileType: "img",
          //   props: {
          //     label: "fileId",
          //     value: "previewUrl",
          //   },
          //   limit: 1,
          //   propsHttp: {
          //     // home: baseUrl,
          //     // res: "data",
          //     name: "fileName",
          //     url: "previewUrl",
          //   },
          //   span: 24,
          //   listType: "picture-card",
          //   action: "app/uploadFile",
          // },
          {
            label: "标题",
            prop: "title",
            search: true,
          },
          {
            label: "类型",
            prop: "type",
            search: true,
            type: "select",
            dicData: [
              {
                label: "地区校友会",
                value: "0",
              },
              {
                label: "年级校友会",
                value: "1",
              },
            ],
          },
          {
            label: "内容",
            prop: "content",
            span: 24,
            hide: true,
            component: "avueUeditor",
            // action: "api/oss/upload",
            action: "app/uploadFile",
            propsHttp: {
              // home: baseUrl,
              // res: "data",
              name: "fileName",
              url: "previewUrl",
            },
          },
          {
            label: "创建时间",
            prop: "createTime",
            display: false,
          },
          {
            label: "更新时间",
            prop: "updateTime",
            display: false,
          },
        ],
      },
      tableData: [],
    };
  },
  methods: {
    rowLoad() {
      org_page(this.params).then((res) => {
        let result = this.$s.res(res);
        this.data = result.records;
        this.page.total = result.totalPage;
      });
    },
    rowSave(row, loading, done) {
      org_add(row)
        .then((res) => {
          this.$s.suc(res);
          this.rowLoad();
          done();
          loading();
        })
        .catch((err) => {
          console.error(err);
          loading();
        });
    },
    rowUpdate(row, index, done, loading) {
      org_edit(row)
        .then((res) => {
          this.$s.suc(res);
          this.rowLoad();
          done();
          loading();
        })
        .catch((err) => {
          console.error(err);
          loading();
        });
    },
    rowDel(row, index, done) {
      this.$confirm("确定数据删除?", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          org_delete({ id: row.id }).then((res) => {
            this.$s.suc(res);
          });
        })
        .then(() => {
          this.rowLoad();
          done();
        });
    },
  },
  mounted() {},
};
</script>

<style lang="less" scoped>
.demo-drawer__content {
  width: 100%;
  padding: 20px;
}
</style>
